package v1

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// CreateMindScaleRes 创建MindScaleRes
// @Tags MindScale
// @Summary 创建MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "创建MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /scaleRes/createMindScale [post]
func CreateMindScaleRes(c *gin.Context) {
	var scaleRes model.MindScaleRes
	_ = c.ShouldBindJSON(&scaleRes)
	if err := service.CreateMindScaleRes(scaleRes); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteMindScaleRes 删除MindScaleRes
// @Tags MindScale
// @Summary 删除MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "删除MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /scaleRes/deleteMindScale [delete]
func DeleteMindScaleRes(c *gin.Context) {
	var scaleRes model.MindScaleRes
	_ = c.ShouldBindJSON(&scaleRes)
	if err := service.DeleteMindScaleRes(scaleRes); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteMindScaleResByIds 批量删除MindScaleRes
// @Tags MindScale
// @Summary 批量删除MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /scaleRes/deleteMindScaleByIds [delete]
func DeleteMindScaleResByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteMindScaleResByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateMindScaleRes 更新MindScaleRes
// @Tags MindScale
// @Summary 更新MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "更新MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /scaleRes/updateMindScale [put]
func UpdateMindScaleRes(c *gin.Context) {
	var scaleRes model.MindScaleRes
	_ = c.ShouldBindJSON(&scaleRes)
	if err := service.UpdateMindScaleRes(scaleRes); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindMindScaleRes 用id查询MindScaleRes
// @Tags MindScale
// @Summary 用id查询MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "用id查询MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /scaleRes/findMindScale [get]
func FindMindScaleRes(c *gin.Context) {
	var scaleRes model.MindScaleRes
	_ = c.ShouldBindQuery(&scaleRes)
	if err, rescaleRes := service.GetMindScaleRes(scaleRes.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"rescaleRes": rescaleRes}, c)
	}
}

// FindMindScaleResByUser 用Userid查询MindScaleRes
// @Tags MindScale
// @Summary 用id查询MindScale
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.MindScale true "用id查询MindScale"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /scaleRes/findMindScale [get]
func FindMindScaleResByUser(c *gin.Context) {
	var scaleRes model.MindScaleRes
	_ = c.ShouldBindQuery(&scaleRes)
	if err, rescaleRes := service.FindMindScaleResByUser(scaleRes.UserID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"rescaleRes": rescaleRes}, c)
	}
}

// GetMindScaleResList 分页获取MindScaleRes列表
// @Tags MindScale
// @Summary 分页获取MindScale列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.MindScaleSearch true "分页获取MindScale列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /scaleRes/getMindScaleList [get]
func GetMindScaleResList(c *gin.Context) {
	var pageInfo request.MindScaleResSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetMindScaleResList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
